using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration.Provider;
using System.Data;
using System.Text;
using BlogEngine.Core.Providers;

namespace BlogEngine.Core.Provider
{
	public class SQLUtil
	{
		/// <summary>
		/// Gets the guids.
		/// </summary>
		/// <param name="query">The query.</param>
		/// <param name="database">The database.</param>
		/// <returns></returns>
		public static List<Guid> GetGuids(string query, string database)
		{
			List<Guid> guids = new List<Guid>();

			SQLManagedConnection myConn = SQLManagedConnection.GetConnection(database);

			try
			{
				myConn.GetTextCommand(query);

				using (IDataReader reader = myConn.ExecuteReader())
				{
					while (reader.Read())
						guids.Add(reader.GetGuid(0));

					reader.Close();
				}
			}
			finally
			{
				myConn.CloseIfNonTransactional();
			}

			return guids;
		}
	}
}
